package com.ebpm.designer.item
{
	import com.ebpm.designer.NodeContainer;
	import com.ebpm.designer.WF;
	import com.ebpm.designer.WP;
	import com.ebpm.designer.line.Line;
	import com.ebpm.designer.line.LineUtil;
	
	import flash.events.MouseEvent;
	
	import mx.collections.ArrayList;
	import mx.containers.Canvas;
	
	/**
	 * UserTask中四个点
	 * */
	public class Item extends Canvas
	{
		public var nodeContainer:NodeContainer;
		public var sourceLines:ArrayList = new ArrayList();																//【源线集合】
		public var targetLines:ArrayList = new ArrayList();																	//【目标线集合】
		
		public function Item(container:NodeContainer) 
		{
			this.nodeContainer = container;
			this.initStyle();
			this.initListener();
			initLocation();
		}
		
		private function initStyle():void {
			this.width = WF.ITEM_SIZE;
			this.height = WF.ITEM_SIZE;
			this.setStyle("borderColor", WF.ITEM_BORDER_COLOR);
			this.setStyle("backgroundColor", WF.ITEM_BGCOLOR);
			this.setStyle("backgroundAlpha", 0.5);
			this.setStyle("borderStyle", "solid");
		}
		
		private function initListener():void{
			this.addEventListener(MouseEvent.MOUSE_OVER, _mouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, _mouseOut);
			this.addEventListener(MouseEvent.MOUSE_DOWN, _mouseDown);
			this.addEventListener(MouseEvent.MOUSE_UP, _mouseUp);
		}
		
		private function _mouseOver(event:MouseEvent):void {
			this.useHandCursor = true;
			this.mouseChildren = false;
			this.buttonMode = true;
			this.setStyle("backgroundColor", WF.ITEM_BG_OVER_COLOR);
			this.nodeContainer.displayItems();
		}
		
		private function _mouseOut(event:MouseEvent):void {
			this.setStyle("backgroundColor", WF.ITEM_BGCOLOR);
			WF.wp.hideNodeContainerItems();
		}
		
		private function _mouseDown(event:MouseEvent):void {
			WP.isDrawingLine = true;
			WP.isAllowSelectNodeContainers = false;
			WF.wp.lineSourceItem = this;
		}
		
		private function _mouseUp(event:MouseEvent):void {
			//画出线
			LineUtil.newLine(WF.wp.lineSourceItem, this);
			WF.wp.lineTargetItem = this;
			WF.wp.hideNodeContainerItems();
		}
		
		public function getPageX():Number {
			return this.nodeContainer.x + this.x;
		}
		
		public function getPageY():Number {
			return this.nodeContainer.y + this.y;
		}
		
		public function setLinesToDefault():void {
			for(var i:int=0; i<this.sourceLines.length; i++) {
				var l:Line = this.sourceLines.getItemAt(i) as Line;
				l.removeDir();																																																																		//隐藏【线 - 移动框】
				
				if(WP.mouseUpX > l.txtInput.x && WP.mouseUpX < l.txtInput.x + l.txtInput.width && WP.mouseUpY > l.txtInput.y && WP.mouseUpY < l.txtInput.y + l.txtInput.height) {					//如果【点击】位置是【输入框】 - 则不隐藏输入框，该事件暂时不做处理
					
				} else {
					l.hidenInput();																																																																	//如果不是点击【输入框】 - 则隐藏【线-输入框】
				}
				
				if(l.isClick) {
					l.isClick = false;																																																																//如果是toggle click line - 则设置【线 - click】 = false
					l.drawLine();
				}
			}
		}
		
		public function initLocation():void {}																																																									//初始化位置信息
		
		public function resizeByNodeContainer():void {}																																																			//根据nodeContainer的width和height变化改变x、y，有子类自己实现
		
		
		
		
	}
}